package com.qdsg.ysg.doctor.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.rest.response.Prescription2Response;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import com.qdsg.ysg.doctor.R;

/**
 * Created by HP on 2020/3/2.
 */

public class MedicineChatAdapter extends RecyclerView.Adapter<MedicineChatAdapter.Holder> {

    Context context;
    List<Prescription2Response.Prescription> list;

    public MedicineChatAdapter(Context context, List<Prescription2Response.Prescription> list) {
        this.context = context;
        this.list = list;
    }


    @Override
    public MedicineChatAdapter.Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        MedicineChatAdapter.Holder myHolder;
        myHolder = new MedicineChatAdapter.Holder(LayoutInflater.from(context).inflate(R.layout.item_chat_medicine, parent, false));
        return myHolder;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(MedicineChatAdapter.Holder holder, final int position) {
        holder.itemView.setOnClickListener(v -> {
//                Bundle bundle = new Bundle();
//                bundle.putSerializable("obj", list.get(position));
//                startActivity(CheckActivity.class, bundle);
        });
        holder.tv_medicine_name.setText( list.get( position ).name );
        holder.tv_medicine_base_num.setText( list.get( position ).drugDose  + "  " + list.get( position ).drugFrequency + "  " + list.get( position ).drugChannel );
        holder.tv_medicine_num.setText( list.get( position ).drugNumber );
        holder.tv_medicine_price.setText( "¥" + list.get( position ).expense );
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class Holder extends RecyclerView.ViewHolder {

        TextView tv_medicine_name, tv_medicine_num, tv_medicine_base_num, tv_medicine_price;

        Holder(View itemView) {
            super( itemView );
            tv_medicine_name = itemView.findViewById( R.id.tv_medicine_name );
            tv_medicine_base_num = itemView.findViewById( R.id.tv_medicine_base_num );//数量
            tv_medicine_num = itemView.findViewById( R.id.tv_medicine_num );
            tv_medicine_price = itemView.findViewById( R.id.tv_medicine_price );
        }
    }
}
